package com.ruoyi.gczl.clzxzl.zljc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gczl.clzxzl.zljc.domain.ClzxzlZljc;
import com.ruoyi.gczl.clzxzl.zljc.service.IClzxzlZljcService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 测量专项资料质量检查Controller
 *
 * @author huacai
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/clzxzl/zljc")
public class ClzxzlZljcController extends BaseController {
    @Resource
    private IClzxzlZljcService clzxzlZljcService;

    /**
     * 查询测量专项资料质量检查列表
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClzxzlZljc clzxzlZljc) {
        startPage();
        List<ClzxzlZljc> list = clzxzlZljcService.selectClzxzlZljcList(clzxzlZljc);
        return getDataTable(list);
    }

    /**
     * 导出测量专项资料质量检查列表
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:export')")
    @Log(title = "测量专项资料质量检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClzxzlZljc clzxzlZljc) {
        List<ClzxzlZljc> list = clzxzlZljcService.selectClzxzlZljcList(clzxzlZljc);
        ExcelUtil<ClzxzlZljc> util = new ExcelUtil<ClzxzlZljc>(ClzxzlZljc.class);
        util.exportExcel(response, list, "测量专项资料质量检查数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<ClzxzlZljc> util = new ExcelUtil<ClzxzlZljc>(ClzxzlZljc.class);
        util.importTemplateExcel(response, "测量专项资料质量检查数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "测量专项资料质量检查", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<ClzxzlZljc> util = new ExcelUtil<ClzxzlZljc>(ClzxzlZljc.class);
        InputStream inputStream = file.getInputStream();
        List<ClzxzlZljc> list = util.importExcel(inputStream);
        inputStream.close();
        int count = clzxzlZljcService.batchInsertClzxzlZljc(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取测量专项资料质量检查详细信息
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:query')")
    @GetMapping(value = "/{clzxzlZljcId}")
    public AjaxResult getInfo(@PathVariable("clzxzlZljcId") Integer clzxzlZljcId) {
        return success(clzxzlZljcService.selectClzxzlZljcByClzxzlZljcId(clzxzlZljcId));
    }

    /**
     * 新增测量专项资料质量检查
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:add')")
    @Log(title = "测量专项资料质量检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClzxzlZljc clzxzlZljc) {
        clzxzlZljc.setUserId(Math.toIntExact(getUserId()));
        clzxzlZljc.setDeptId(Math.toIntExact(getDeptId()));
        clzxzlZljc.setCreateBy(getUsername());

        return toAjax(clzxzlZljcService.insertClzxzlZljc(clzxzlZljc));
    }

    /**
     * 修改测量专项资料质量检查
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:edit')")
    @Log(title = "测量专项资料质量检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClzxzlZljc clzxzlZljc) {
        return toAjax(clzxzlZljcService.updateClzxzlZljc(clzxzlZljc));
    }

    /**
     * 删除测量专项资料质量检查
     */
    @PreAuthorize("@ss.hasPermi('clzxzl:zljc:remove')")
    @Log(title = "测量专项资料质量检查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{clzxzlZljcIds}")
    public AjaxResult remove(@PathVariable Integer[] clzxzlZljcIds) {
        return toAjax(clzxzlZljcService.deleteClzxzlZljcByClzxzlZljcIds(clzxzlZljcIds));
    }
}
